﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XGE.Console
{
    public class ConsoleWindow : DrawableGameComponent
    {

        #region Memebers
        enum Sizes
        {
            Full = 1,
            Half = 2,
            Third = 3
        }
        private Sizes DrawSize = Sizes.Half;
        private int WindowHeight;
        private int WidowWidth;
        private int MaxLines;

        /// <summary>
        /// The maximum number of drawable Lines;
        /// </summary>
        private int DrawableLines
        {
            get { return (MaxLines / (int)DrawSize) - 1; }
        }
        private OutputCollection ConsoleOutput;
        private SpriteFont Outputfont;

        #endregion 

        

        public ConsoleWindow(SpriteFont Font, int WindowHeight, int WindowWidth)
        {
            this.WindowHeight = WindowHeight;
            this.WidowWidth = WindowWidth;
            Outputfont = Font;
            ConsoleOutput = new OutputCollection();
            init();
        }

        public override void Initialize()
        {
            Game.Content.Load<SpriteFont>("TestFont");
            base.Initialize();
        } 

        public void AddLine(string Line)
        {
            ConsoleOutput.AddNewLine(Line);
        }

        public void Resize()
        {
            switch (DrawSize)
            {
                case Sizes.Full:
                    DrawSize = Sizes.Half;
                    break;
                case Sizes.Half:
                    DrawSize = Sizes.Third;
                    break;
                default:
                    DrawSize = Sizes.Full;
                    break;
            }
            ConsoleOutput.MaxLineOutput = DrawableLines;
            ConsoleOutput.Resize();

        }

        private void init()
        {
            MaxLines = (WindowHeight / Outputfont.LineSpacing);
            ConsoleOutput.MaxLineOutput = DrawableLines;

        }
        public void ScrollUp()
        {
            ConsoleOutput.ScrollUp();
        }
        public void ScrollDown()
        {
            ConsoleOutput.ScrollDown();
        }
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = 
            List<string> Output = ConsoleOutput.GetOutput();
            int LineCount = 0;
            foreach (string Text in Output)
            {
                GraphicsDevice. .DrawString(Outputfont, Text, new Vector2(0, LineCount * Outputfont.LineSpacing), Color.Black);
                LineCount++;
            }
            base.Draw(gameTime);
        }
        public void Draw(SpriteBatch spriteBatch)
        {
            

        }
    }
}
